<?php
/**
 * Created on 26 mars 08 by Eric Jeker <eric.jeker@gmail.com>
 * Created on Eclipse 3.2 with PHPEclipse 1.1.8
 * (c) 2007 - 2008 Copyright Eric Jeker <eric.jeker@gmail.com>
**/

use_helper('Date') ;
?>

<table cellpadding="0" cellspacing="0" border="0">
<?php foreach ($challenges as $challenge) { ?>
<tr>
	<td>
	  <?php echo link_to($challenge->getP1()->getUsername(), 'player/details?player=' . $challenge->getP1Id()) ?>
		challenged
		<?php echo link_to($challenge->getP2()->getUsername(), 'player/details?player=' . $challenge->getP2Id()) ?>
		at
		<?php echo format_date($challenge->getCreatedAt()) ?> and
		<?php echo $challenge->getIsDraw() == 1 ? " it's a draw" : 'won' ?>
	</td>

	<? if ($sf_user->isAuthenticated() && $challenge->getP2Id() == $sf_user->getGuardUser()->getId()) { ?>
		<td>
			<?php echo form_tag('challenge/validate') ?>
				<?php echo input_hidden_tag('challenge', $challenge->getId()) ?>
				<?php echo submit_image_tag('/web/images/accept.png', array(
					'onclick' => "if (!confirm('Are you sure you want to validate this challenge ?')) return false ;"
				)) ?>
			</form>
		</td><td>
			<?php echo form_tag('challenge/refuse') ?>
				<?php echo input_hidden_tag('challenge', $challenge->getId()) ?>
				<?php echo submit_image_tag('/web/images/delete.png', array(
					'onclick' => "if (!confirm('Are you sure you want to refuse this challenge ?')) return false ;"
				)) ?>
			</form>
		</td>
	<? } else { ?>
		<td colspan="2">validation needed !</td>
	<? } ?>
</tr>
<?php } ?>
</table>
